package rs.pnv.model.payment;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.URL;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_PAYMENT_URL_REQUEST")
@XmlAccessorType(XmlAccessType.FIELD)
public class PaymentUrlRequest extends AbstractEntity {

	@NotBlank
	@OneToOne
	@JoinColumn(nullable = false)
	@XmlElement(nillable = false)
	private Merchant merchant;

	@NotBlank
	@OneToOne
	@JoinColumn(nullable = false)
	@XmlElement(nillable = false)
	private Transaction transaction;

	@URL
	private String errorUrl;

	public PaymentUrlRequest() {

	}

	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	public Transaction getTransaction() {
		return transaction;
	}

	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;
	}

	public String getErrorUrl() {
		return errorUrl;
	}

	public void setErrorUrl(String errorUrl) {
		this.errorUrl = errorUrl;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(errorUrl)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final PaymentUrlRequest otherPaymentRequest = (PaymentUrlRequest) obj;

		return new EqualsBuilder()
				.append(errorUrl, otherPaymentRequest.getErrorUrl())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("errorUrl", errorUrl)
				.append(super.toString())
				.toString();
	}
}
